package Queue;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-03-05
 * Time:17:36
 * Text：层序遍历
 */
public class Text1 {
    public List<List<Integer>> levelOrder(Node root) {
        List<List<Integer>> list=new ArrayList<>();
        Queue<Node> t1=new ArrayDeque<>();
        t1.add(root);
        while(!t1.isEmpty()){
            int sz=t1.size();
            List<Integer> l2=new ArrayList<>();
            for(int i=0;i<sz;i++){
                Node t=t1.poll();
                l2.add(t.val);
                for(Node t2:t.children){
                    if(t2!=null){
                        t1.add(t2);
                    }
                }
            }
            list.add(l2);
        }
        return list;
    }
}
